<template>
  <div>
    <el-dialog
      title="工单详情"
      :visible.sync="dialogVisible"
      width="45%"
    >
      <div class="detail">
        <div class="todo">
          <img v-if="orderdata.taskStatus===1" src="@/assets/time.png" alt="" class="image">
          <img v-if="orderdata.taskStatus===3" src="@/assets/cancel.png" alt="" class="image">
          <span class="text">{{ orderdata.taskStatus===1? '待办':orderdata.taskStatus===2? '进行':orderdata.taskStatus===3? '取消':'' }}</span>
          <img v-if="orderdata.taskStatus===1" src="https://likede2-admin.itheima.net/img/pic_1.834b274c.png" alt="" class="images">
          <img v-if="orderdata.taskStatus===3" src="https://likede2-admin.itheima.net/img/pic_3.e8208e34.png" alt="" class="images">
        </div>
        <!-- 待办 -->
        <div v-if="orderdata.taskStatus===1">
          <el-row>
            <el-col :span="12">
              <div class="left">
                <p>设备编号：<span>{{ orderdata.innerCode }}</span></p>
                <p>运维人员：<span>{{ orderdata.userName }}</span></p>
                <p>工单方式：<span>{{ orderdata.createType? '手动':'自动' }}</span></p>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="left">
                <p>创建日期：<span>{{ orderdata.createTime.replace('T',' ') }}</span></p>
                <p>工单类型：<span>{{ orderdata.productTypeId===1? '投放工单':orderdata.productTypeId===2? '补货工单':orderdata.productTypeId===3? '维修工单':'撤机工单' }}</span></p>
                <p>备注：<span>{{ orderdata.desc }}</span></p>
              </div>
            </el-col>
          </el-row>
        </div>
        <!-- 取消 -->
        <div v-if="orderdata.taskStatus===3">
          <el-row>
            <el-col :span="12">
              <div class="left">
                <p>设备编号：<span>{{ orderdata.innerCode }}</span></p>
                <p>取消日期：<span>{{ orderdata.updateTime.replace('T',' ') }}</span></p>
                <p>工单类型：<span>{{ orderdata.productTypeId===1? '投放工单':orderdata.productTypeId===2? '补货工单':orderdata.productTypeId===3? '维修工单':'撤机工单' }}</span></p>
                <p>取消原因：<span>{{ orderdata.desc }}</span></p>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="left">
                <p>创建日期：<span>{{ orderdata.createTime.replace('T',' ') }}</span></p>
                <p>运维人员：<span>{{ orderdata.userName }}</span></p>
                <p>工单方式：<span>{{ orderdata.createType? '手动':'自动' }}</span></p>
              </div>
            </el-col>
          </el-row>
        </div>

      </div>

      <span slot="footer">
        <div class="foot">
          <el-button v-if="orderdata.taskStatus===1" style="background-color: #fbf4f0;color: #606266;" @click="cancel">取消订单</el-button>
          <el-button v-if="orderdata.taskStatus===3" style="background-color: #fbf4f0;color: #606266;" @click="recreate">重新创建</el-button>
        </div>
      </span>
    </el-dialog>

    <!-- 新增弹窗 -->
    <DialogLm ref="add" />
  </div>
</template>

<script>
import { getOrderDetail, getOrderCancel } from '@/api/lmoperation'

import DialogLm from './dialog.vue'

export default {
  name: 'OrderDetail',
  components: {
    DialogLm
  },
  props: {
  },
  data() {
    return {
      dialogVisible: false,
      // 工单详情
      orderdata: {}
    }
  },
  methods: {
    // 弹窗显示
    openDialogK() {
      this.dialogVisible = true
    },
    // 弹窗关闭
    offDialogG() {
      this.dialogVisible = false
    },
    // 获取工单的详情
    async getOrdersDetail(taskId) {
      const data = await getOrderDetail(taskId)
      this.orderdata = { ...data }
      // console.log(data)
    },
    // 取消
    cancel() {
      this.$confirm('取消工单后,将不能恢复， 是否确认取消?', '', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await getOrderCancel(this.orderdata)
        this.$message.success('取消成功!')
        this.offDialogG()
        this.$emit('gitlist')
        // this.dialogVisible = false
      }).catch(() => {
        console.log('取消')
      })
    },
    // 重新创建
    recreate() {
      // console.log('add')
      this.$refs.add.openDialogK(this.orderdata.taskId)
    }
  }
}
</script>

<style scoped lang='scss'>
.foot{
  padding-right: 42%;
}
.detail{
  width: 100%;
  height: 200px;
  .todo{
    width: 100%;
    height: 50px;
    line-height: 50px;
    background-color: #f8f8f8;
    margin-bottom: 20px;
    padding-left: 20px;
    padding-right: 80px;
    .image{
      vertical-align: middle;
    }
    .text{
      font-size: 16px;
      margin-left: 10px;
      display: inline-block;
      vertical-align: middle;
    }
    .images{
      width: 14%;
      float: right;
    }
  }
  .left{
    padding-left: 50px;
  }
}
</style>
